package me.eleme.anubis.openapi.oauth.request;

import me.eleme.anubis.openapi.config.Config;
import me.eleme.anubis.openapi.config.Constants;
import me.eleme.anubis.openapi.config.oauth.response.Token;
import me.eleme.anubis.openapi.oauth.BaseOauthRequest;

import java.util.Map;

/**
 * @author liuzhiyong
 */
public class ServerRefreshTokenRequest extends BaseOauthRequest {

    private Config context;

    private String merchantId;

    private String timestamp;

    private String signature;
    public ServerRefreshTokenRequest(Config context) {
        this.context = context;
    }
    private String refreshToken;

    @Override
    public Class<Token> getResponseClass() {
        return Token.class;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public Config getContext() {
        return context;
    }

    public void setContext(Config context) {
        this.context = context;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    @Override
    public Map<String, String> getHeaderMap() {
        setAuthorization(context.getAppId(), context.getSecretKey(), Constants.TOKEN_SIGN);
        return super.headerMap;
    }


    @Override
    public Map<String, String> getBodyMap() {
        putBodyParam("grant_type", "refresh_token");
        putBodyParam("merchant_id", this.getMerchantId());
        putBodyParam("app_id", context.getAppId());
        putBodyParam("timestamp", this.getTimestamp());
        putBodyParam("signature", this.getSignature());
        putBodyParam("refresh_token", this.refreshToken);
        return super.bodyMap;
    }
}
